package com.hangoverstudios.batterysaver;

import android.content.Context;
import android.content.SharedPreferences;

public class Helper {
	
	public static final String Pref_Names = "battery_doctor";
	
	public static final String wifi_key = "wifi";
	public static final String bluetooth_key = "bluetooth";
	public static final String brightness_key = "brightness";
	public static final String vibration_key = "vibration";
	public static final String mobile_key = "mobiledata";
	public static final String brightness_state_key = "brightness_state";
	public static final String wifi_state_key = "wifi_state";
	public static final String bluetooth_state_key = "bluetooth_state";
	public static final String vibration_state_key = "vibration_state";
	public static final String mobile_state_key = "mobile_state";
	public static final String power_save_mode_key = "power_save_mode";
	
	
	Context context;
	
	public Helper(Context context)
	{
		this.context = context;
	}
	
	public boolean isWifiSaverEnabled()
	{
		SharedPreferences preferences = context.getApplicationContext().getSharedPreferences(Pref_Names, Context.MODE_PRIVATE);
		return preferences.getBoolean(wifi_key, false);
	}
	public boolean isPowerSaveModeOn()
	{
		SharedPreferences preferences = context.getApplicationContext().getSharedPreferences(Pref_Names, Context.MODE_PRIVATE);
		return preferences.getBoolean(power_save_mode_key, false);
	}
	public boolean isBTSaverEnabled()
	{
		SharedPreferences preferences = context.getApplicationContext().getSharedPreferences(Pref_Names, Context.MODE_PRIVATE);
		return preferences.getBoolean(bluetooth_key, false);
	}
	public boolean isBrightnessSaverEnabled()
	{
		SharedPreferences preferences = context.getApplicationContext().getSharedPreferences(Pref_Names, Context.MODE_PRIVATE);
		return preferences.getBoolean(brightness_key, false);
	}
	public boolean isMobileDataSaverEnabled()
	{
		SharedPreferences preferences = context.getApplicationContext().getSharedPreferences(Pref_Names, Context.MODE_PRIVATE);
		return preferences.getBoolean(mobile_key, false);
	}
	public boolean isVibrationSaverEnabled()
	{
		SharedPreferences preferences = context.getApplicationContext().getSharedPreferences(Pref_Names, Context.MODE_PRIVATE);
		return preferences.getBoolean(vibration_key, false);
	}
	
	public void saveWifiSaverEnabled(boolean enabled)
	{
		SharedPreferences preferences = context.getApplicationContext().getSharedPreferences(Pref_Names, Context.MODE_PRIVATE);
		SharedPreferences.Editor editor = preferences.edit();
		editor.putBoolean(wifi_key, enabled);			
		editor.commit();
	}
	public void savePowerSaveModeEnabled(boolean enabled)
	{
		SharedPreferences preferences = context.getApplicationContext().getSharedPreferences(Pref_Names, Context.MODE_PRIVATE);
		SharedPreferences.Editor editor = preferences.edit();
		editor.putBoolean(power_save_mode_key, enabled);			
		editor.commit();
	}
	public void saveBTSaverEnabled(boolean enabled)
	{
		SharedPreferences preferences = context.getApplicationContext().getSharedPreferences(Pref_Names, Context.MODE_PRIVATE);
		SharedPreferences.Editor editor = preferences.edit();
		editor.putBoolean(bluetooth_key, enabled);			
		editor.commit();
	}
	public void saveMobileDataSaverEnabled(boolean enabled)
	{
		SharedPreferences preferences = context.getApplicationContext().getSharedPreferences(Pref_Names, Context.MODE_PRIVATE);
		SharedPreferences.Editor editor = preferences.edit();
		editor.putBoolean(mobile_key, enabled);			
		editor.commit();
	}
	public void saveVibrationSaverEnabled(boolean enabled)
	{
		SharedPreferences preferences = context.getApplicationContext().getSharedPreferences(Pref_Names, Context.MODE_PRIVATE);
		SharedPreferences.Editor editor = preferences.edit();
		editor.putBoolean(vibration_key, enabled);			
		editor.commit();
	}
	public void saveBrightnessSaverEnabled(boolean enabled)
	{
		SharedPreferences preferences = context.getApplicationContext().getSharedPreferences(Pref_Names, Context.MODE_PRIVATE);
		SharedPreferences.Editor editor = preferences.edit();
		editor.putBoolean(brightness_key, enabled);			
		editor.commit();
	}
	public void saveBrightnessState(int value)
	{
		SharedPreferences preferences = context.getApplicationContext().getSharedPreferences(Pref_Names, Context.MODE_PRIVATE);
		SharedPreferences.Editor editor = preferences.edit();
		editor.putInt(brightness_state_key, value);			
		editor.commit();
	}
	public void saveWifiState(boolean enabled)
	{
		SharedPreferences preferences = context.getApplicationContext().getSharedPreferences(Pref_Names, Context.MODE_PRIVATE);
		SharedPreferences.Editor editor = preferences.edit();
		editor.putBoolean(wifi_state_key, enabled);			
		editor.commit();
	}
	public void saveBTState(boolean enabled)
	{
		SharedPreferences preferences = context.getApplicationContext().getSharedPreferences(Pref_Names, Context.MODE_PRIVATE);
		SharedPreferences.Editor editor = preferences.edit();
		editor.putBoolean(bluetooth_state_key, enabled);			
		editor.commit();
	}
	public void saveMobileDataState(boolean enabled)
	{
		SharedPreferences preferences = context.getApplicationContext().getSharedPreferences(Pref_Names, Context.MODE_PRIVATE);
		SharedPreferences.Editor editor = preferences.edit();
		editor.putBoolean(mobile_state_key, enabled);			
		editor.commit();
	}
	public void saveVibrationState(boolean enabled)
	{
		SharedPreferences preferences = context.getApplicationContext().getSharedPreferences(Pref_Names, Context.MODE_PRIVATE);
		SharedPreferences.Editor editor = preferences.edit();
		editor.putBoolean(vibration_state_key, enabled);			
		editor.commit();
	}
	
	public boolean getSavedWifiState()
	{
		SharedPreferences preferences = context.getApplicationContext().getSharedPreferences(Pref_Names, Context.MODE_PRIVATE);
		return preferences.getBoolean(wifi_state_key, false);
	}
	public boolean getSavedBTState()
	{
		SharedPreferences preferences = context.getApplicationContext().getSharedPreferences(Pref_Names, Context.MODE_PRIVATE);
		return preferences.getBoolean(bluetooth_state_key, false);
	}
	public boolean getSavedVibrationState()
	{
		SharedPreferences preferences = context.getApplicationContext().getSharedPreferences(Pref_Names, Context.MODE_PRIVATE);
		return preferences.getBoolean(vibration_state_key, false);
	}
	public boolean getSavedMobileDataState()
	{
		SharedPreferences preferences = context.getApplicationContext().getSharedPreferences(Pref_Names, Context.MODE_PRIVATE);
		return preferences.getBoolean(mobile_state_key, false);
	}
	public int getSavedBrightnessState()
	{
		SharedPreferences preferences = context.getApplicationContext().getSharedPreferences(Pref_Names, Context.MODE_PRIVATE);
		return preferences.getInt(brightness_state_key, 20);
	}
}




